package com.tuozq.service.impl;

import com.tuozq.pojo.Product;
import com.tuozq.service.ProductService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    /**
     * 模拟数据源
     */
    private List<Product> DB_LIST = Arrays.asList(
            new Product("1", "商品A", new BigDecimal(10), new BigDecimal(100)),
            new Product("2", "商品B", new BigDecimal(20), new BigDecimal(1001)),
            new Product("4", "商品C", new BigDecimal(10), new BigDecimal(1005)),
            new Product("4", "商品D", new BigDecimal(50), new BigDecimal(1008)),
            new Product("5", "商品E", new BigDecimal(10), new BigDecimal(1009))
    );

    /**
     * 获取全部商品
     * @return
     */
    @Override
    public List<Product> selectProduct() {
        return DB_LIST;
    }

    /**
     * 通过商品ID获取商品信息
     * @param id
     * @return
     */
    @Override
    public Product selectProductById(String id) {
        for (Product product : DB_LIST){
            if (product.getId().equals(id)){
                return product;
            }
        }
        return null;
    }

}
